package com.lh0811.forge.pserv.cgen.server.component;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Getter
@Setter
public class CodeGenConfig implements Serializable {

    private String packageName = "com.lh0811.forge.pserv.ebus.server.repository";
    private String dbUrl = "jdbc:mysql://127.0.0.1:3306/tech-forge-dev";
    private String dbUsername = "root";
    private String dbPassword = "123456";
    private String path = "/Users/lh0811/Desktop";
    private String fileName = "tmp.zip";
    private String[] prefix = new String[]{"t_"};

    private Map<String, String> tableMap = new HashMap<>();
    private List<String> templates = new ArrayList<String>();

    {
        tableMap.put("tinyint", "Integer");
        tableMap.put("tinyint_1", "Boolean");
        tableMap.put("smallint", "Integer");
        tableMap.put("mediumint", "Integer");
        tableMap.put("int", "Integer");
        tableMap.put("integer", "Integer");
        tableMap.put("bigint", "Long");
        tableMap.put("float", "Float");
        tableMap.put("double", "Double");
        tableMap.put("decimal", "BigDecimal");
        tableMap.put("bit", "Boolean");
        tableMap.put("char", "String");
        tableMap.put("varchar", "String");
        tableMap.put("tinytext", "String");
        tableMap.put("text", "String");
        tableMap.put("mediumtext", "String");
        tableMap.put("longtext", "String");
        tableMap.put("date", "Date");
        tableMap.put("datetime", "Date");
        tableMap.put("timestamp", "Date");
        tableMap.put("NUMBER", "Integer");
        tableMap.put("INT", "Integer");
        tableMap.put("INTEGER", "Integer");
        tableMap.put("BINARY_INTEGER", "Integer");
        tableMap.put("LONG", "String");
        tableMap.put("FLOAT", "Float");
        tableMap.put("BINARY_FLOAT", "Float");
        tableMap.put("DOUBLE", "Double");
        tableMap.put("BINARY_DOUBLE", "Double");
        tableMap.put("DECIMAL", "BigDecimal");
        tableMap.put("CHAR", "String");
        tableMap.put("VARCHAR", "String");
        tableMap.put("VARCHAR2", "String");
        tableMap.put("NVARCHAR", "String");
        tableMap.put("NVARCHAR2", "String");
        tableMap.put("CLOB", "String");
        tableMap.put("BLOB", "String");
        tableMap.put("DATE", "Date");
        tableMap.put("DATETIME", "Date");
        tableMap.put("TIMESTAMP", "Date");
        tableMap.put("int8", "Long");
        tableMap.put("int4", "Integer");
        tableMap.put("int2", "Integer");
        tableMap.put("numeric", "BigDecimal");
        tableMap.put("nvarchar", "String");


        templates.add("template/Entity.java.vm");
        templates.add("template/Mapper.java.vm");
        templates.add("template/Dao.java.vm");
        templates.add("template/DaoImpl.java.vm");
    }

    // 私有静态实例
    private static volatile CodeGenConfig instance;

    // 私有构造函数，防止外部实例化
    private CodeGenConfig() {
        // 初始化代码
    }

    // 提供公共静态方法获取实例
    public static CodeGenConfig getInstance() {
        if (instance == null) {
            synchronized (CodeGenConfig.class) {
                if (instance == null) {
                    instance = new CodeGenConfig();
                }
            }
        }
        return instance;
    }

}
